﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YouHP.Model
{
    public class SymptomSearchConditon
    {
        public string SymptomName { get; set; } //症状名称
        public string DiseaseName { get; set; } //疾病名称
        public int DiseaseId { get; set; }      //疾病id

        public string NoAllowed { get; set; } //不允许出现的病症

        public SymptomSearchConditon()
        {
            SymptomName = DiseaseName = NoAllowed = string.Empty;
            DiseaseId = -1;
        }

        public string ToSqlConditonString()
        {
            string sql = string.Empty;
            bool firstCond = true;

            if (SymptomName.Length > 0)
            {
                sql = string.Format(" [Symptom].[SymptomName] like '%{0}%' ", SymptomName);
                firstCond = false;
            }

            if (DiseaseId > 0)
            {
                if(!firstCond)
                {
                    sql += " and ";
                }

                firstCond = false;  
                sql += string.Format(" [DiseaseSymptom].[DiseaseId] = {0} ", DiseaseId);
            }

            if (NoAllowed.Length > 0 )
            {
                if (!firstCond)
                {
                    sql += " and ";
                }

                firstCond = false;
                sql += string.Format("( [Symptom].[Id] not in ({0}) ) ", NoAllowed);
            }

            return sql;
        }
    }
}
